#ifndef F_CAEmuGSC_h
#define F_CAEmuGSC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCAEmuGSSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, EmuGSDoublePackList, STMTCPackList, STMDoublePackList, SFinalTCPackets, STCPackList, SNoAnswer, SRxBurst, SRxDataBurst, SAnswer, STxBurst, STxDataBurst };


	friend class CAEmuGS;

	CAEmuGS &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SgiTMTCServer;
	CEDROOMInterface & SGIGround;

	enum edroomStateId{I, Ready};

	enum IdTrans{Init, ListeningDataBurst, ListeningDataBurst_DSRxDataBurst, ListeningDataBurst_DSRxBurst, ListeningDataBurst_DSNoAnswer, ListeningBurst, ListeningBurst_SRxDataBurst, ListeningBurst_SNoAnswer, ListeningBurst_SRxBurst, ReceiveTCLists,  EDROOMMEMORIA };

	//Constantes

	const int VClengthDataFrames;
	const int VClengthFinalFrame;


	//Variables

	word32_t &VAcks;
	byte_t &VAltBit;
	bool_t &VAlternate;
	bool_t &VFaseDos;
	BurstTypeReceived_t &VBurstType;
	CDDataBurst &VDataBurst;
	CPackListHandler &VFreePackList;
	int &VmessageNumber;
	CPackListHandler &VTCPackList;


	//Pool

	class CEDROOMPOOLCDBurst:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDBurst(TEDROOMUInt32 elemCount,CDBurst *pMem, TEDROOMBool *pMarks);
		CDBurst	* AllocData();
	};
	CEDROOMPOOLCDBurst	& CEDROOMPoolCDBurst;
	class CEDROOMPOOLCDDataBurst:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDDataBurst(TEDROOMUInt32 elemCount,CDDataBurst *pMem, TEDROOMBool *pMarks);
		CDDataBurst	* AllocData();
	};
	CEDROOMPOOLCDDataBurst	& CEDROOMPoolCDDataBurst;


	// CONSTRUCTORES

	EDROOMTopContext (CAEmuGS &act, word32_t & EDROOMpVarVAcks, byte_t & EDROOMpVarVAltBit, bool_t & EDROOMpVarVAlternate,bool_t & EDROOMpVarVFaseDos, BurstTypeReceived_t & EDROOMpVarVBurstType, CDDataBurst & EDROOMpVarVDataBurst, CPackListHandler & EDROOMpVarVFreePackList, int & EDROOMpVarVmessageNumber, CPackListHandler & EDROOMpVarVTCPackList, CEDROOMPOOLCDBurst & EDROOMpPoolCDBurst, CEDROOMPOOLCDDataBurst & EDROOMpPoolCDDataBurst );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FCheckTMAcks(bool_t *pAcksOk,bool_t *allOk,byte_t num, CPackListHandler &packList);

	bool_t	GIsSRxDataBurst();

	bool_t	GIsSRxBurst();

	void	FIntToChar(int32_t num,byte_t * cConvert);

	void	FListening();

	void	FPrepareNextTC();

	void	FReceiveAndRespondBurst();

	void	FReceiveAndRespondDataBurst();

	void	FReceiveTCLists();

	void	FSendDSRxBurst();

	void	FSendDSRxDataBurst();

	void	FSendNoAnswer();

	void	FSendSRxDataBurst();

	void	FSendSRxBurst();

	void	FStoreTMFrame(byte_t * frames);

	bool_t	GIsDSRxBurst();

	bool_t	GIsDSRxDataBurst();

	void	FCopyPacks();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	word32_t VAcks;
	byte_t VAltBit;
	bool_t VAlternate;
	bool_t VFaseDos;
	BurstTypeReceived_t VBurstType;
	CDDataBurst VDataBurst;
	CPackListHandler VFreePackList;
	int VmessageNumber;
	CPackListHandler VTCPackList;


	//Pools

	CEDROOMPOOLCDBurst	CEDROOMPoolCDBurst;
	CEDROOMPOOLCDDataBurst	CEDROOMPoolCDDataBurst;


public:

	// CONSTRUCTOR

	EDROOMTopState (CAEmuGS &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Ready

	// ***********************************************************************



	TEDROOMTransId EDROOMReadyllegada();

};


#endif
